local jianjie = fk.CreateSkill{
    name = "wk_heg__jianjie",
}

Fk:loadTranslationTable{
    ["wk_heg__jianjie"] = "荐杰",
    [":wk_heg__jianjie"] = "当你首次明置此武将牌后，你<a href=':ElectedChange'>推举</a>两次，以此法第一次/第二次选用的角色获得“火计”/“连环”直至其发动选用武将牌上的技能。",

    ["@wk_heg__jianjie1"] = "荐杰 火计",
    ["@wk_heg__jianjie2"] = "荐杰 连环",

    ["$wk_heg__jianjie1"] = "卧龙凤雏，二者得一，可安天下。",
    ["$wk_heg__jianjie2"] = "二人齐聚，汉室可兴。",
}

local HG = require "packages/new_heg_diy_my/util"

jianjie:addEffect(fk.GeneralRevealed,{
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    if player:usedSkillTimes(jianjie.name, Player.HistoryGame) == 0 and player:hasSkill(jianjie.name) then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), jianjie.name) then 
          return true 
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, jianjie.name, "support")
    player:broadcastSkillInvoke(jianjie.name)
    for i = 1, 2, 1 do
      local p_table = HG.DoElectedChange(room, player, jianjie.name)
      if p_table then
        local p_player = p_table[1]
        local p_general = p_table[2]
        if i == 1 and p_player then
          room:setPlayerMark(p_player, "@wk_heg__jianjie1", p_general)
          room:handleAddLoseSkills(p_player, "wk_heg__huoji", nil)
        elseif i == 2 and p_player then
          room:setPlayerMark(p_player, "@wk_heg__jianjie2", p_general)
          room:handleAddLoseSkills(p_player, "wk_heg__lianhuan", nil)
        end
      end
    end
  end,
})

jianjie:addEffect(fk.AfterSkillEffect,{
  is_delay_effect = true,
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    if player == target and target:getMark("@wk_heg__jianjie2") ~= 0 then
      local general2 = target:getMark("@wk_heg__jianjie2")
      return table.contains(Fk.generals[general2]:getSkillNameList(), data.skill.name)
    end
    if player == target and target:getMark("@wk_heg__jianjie1") ~= 0 then
      local general1 = target:getMark("@wk_heg__jianjie1")
      return table.contains(Fk.generals[general1]:getSkillNameList(), data.skill.name)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local general1 = target:getMark("@wk_heg__jianjie1")
    local general2 = target:getMark("@wk_heg__jianjie2")
    if general1 ~= 0 and table.contains(Fk.generals[general1]:getSkillNameList(), data.skill.name) then
      room:setPlayerMark(target, "@wk_heg__jianjie1", 0)
      room:handleAddLoseSkills(target, "-wk_heg__huoji")
    end
    if general2 ~= 0 and table.contains(Fk.generals[general2]:getSkillNameList(), data.skill.name) then
      room:setPlayerMark(target, "@wk_heg__jianjie2", 0)
      room:handleAddLoseSkills(target, "-wk_heg__lianhuan")
    end
  end,
})

return jianjie